package redis

import (
	"cart_srv/app_config"
	"fmt"
	"github.com/go-redis/redis"
)

var (
	redisClient *redis.Client
	err         error
)

func InitRedis() {
	app := app_config.AppConf.RedisConfig
	addr := fmt.Sprintf("%s:%d", app.Host, app.Port)
	redisClient = redis.NewClient(&redis.Options{
		Addr:     addr,
		Password: app.Password, // no password set
		DB:       app.DB,       // use default DB
	})

	_, err = redisClient.Ping().Result()
	if err != nil {
		fmt.Println("缓存链接失败", err)
		return
	}
	fmt.Println("缓存链接成功", redisClient)
	// Output: PONG <nil>
}
